/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exercises.day01.pt3;

import java.util.Scanner;

/**
 * MyFirstJava
 *
 * @author (jaice)
 * @version 0.1 (may 28, 2012)
 * 
 * c. Design and implement an application that creates a histogram 
 * that allows you to visually inspect the frequency distribution 
 * of a set of values. The program should read in an arbitrary number 
 * of integers that are in the range 1 to 100 inclusive; then produce 
 * a chart similar to the one below that indicates how many input values
 * fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for 
 * each value entered.
 * 1 - 10   | *****
 * 11 - 20  | **
 * 21 - 30  | *******************
 * 31 - 40  |
 * 41 - 50  | ***
 * 51 - 60  | ********
 * 61 - 70  | **
 * 71 - 80  | *****
 * 81 - 90  | *******
 * 91 - 100 | *********
 *
 * 
 */
public class HistogramViewer {

    public static void main(String args[]) {
        //declare variable
        int[] range = new int[10];
        int input = 0;
        int z = 0;

        //initialize array to 0
        for (int x = 0; x <= 9; x++) {
            range[x] = 0;
        }

        //inform user negative to exit
        System.out.println("Enter any number. Enter <0 to exit");

        //declare scanner
        Scanner sc = new Scanner(System.in);


        do {
            //get input
            input = sc.nextInt();

            //if in range  1-99
            if (input > 0 && input < 100) {
                z = input / 10;
                range[z] = range[z] + 1;
            }
            //if 100 auto add to 90-100
            if (input == 100) {
                range[9]++;
            }




        } while (input > 0);


        //print out histogram
        for (int x = 0; x <= 9; x++) {
            System.out.print("\n" + ((x * 10) + 1) + " to " + ((x * 10) + 10) + " = || ");

            //number of *
            for (int y = 1; y <= range[x]; y++) {
                System.out.print("*");
            }


        }



    }
}
